package com.imut.oa.controller.admin;


import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.PageResult;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.NoticeAddDTO;
import com.imut.oa.pojo.dto.NoticePageQueryDTO;
import com.imut.oa.service.NoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/notice")
@Slf4j
@Tag(name = "公告管理")
public class NoticeController {
    @Resource
    private NoticeService noticeService;

    /**
     * 公告分页查询
     * @param noticePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "公告分页查询")
    public BaseResponse<PageResult> page(NoticePageQueryDTO noticePageQueryDTO) {
        log.info("分页查询：{}", noticePageQueryDTO);
        PageResult pageResult = noticeService.page(noticePageQueryDTO);
        return ResultUtils.success(pageResult);
    }

    /**
     * 新增公告
     * @param noticeAddDTO
     * @return
     */
    @PostMapping
    public BaseResponse add(@RequestBody NoticeAddDTO noticeAddDTO) {
        log.info("新增公告：{}", noticeAddDTO);
        noticeService.save(noticeAddDTO);
        return ResultUtils.success();
    }

    /**
     * 删除公告
     * @param id
     * @return
     */
    @DeleteMapping()
    public BaseResponse remove(Long id) {
        log.info("删除公告：{}", id);
        noticeService.removeNoticeById(id);
        return ResultUtils.success();
    }
}